package ${package.ServiceImpl};

import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyxx.common.utils.LayTableResult;
import com.zyxx.common.utils.ResponseResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
<#if kotlin>
open class ${table.serviceImplName} : ServiceImpl<${table.mapperName}, ${entity}>(), ${table.serviceName} {

}
<#else>
public class ${table.serviceImplName} extends ServiceImpl<${table.mapperName}, ${entity}> implements ${table.serviceName} {



    /**
    * 分页查询
    */
    @Override
    public LayTableResult list(Integer page, Integer limit, ${entity}  ${entity?uncap_first}) {
      LambdaQueryWrapper<${entity}> queryWrapper = new LambdaQueryWrapper<>();
      <#list table.fields as field>
          <#if field.propertyType == "String">
              if (StringUtils.isNotEmpty(${entity?uncap_first}.get${field.capitalName}())) {
                    queryWrapper.eq(${entity}::get${field.capitalName}, ${entity?uncap_first}.get${field.capitalName}());
              }
           <#else>
               if(${entity?uncap_first}.get${field.capitalName}() != null) {
                    queryWrapper.eq(${entity}::get${field.capitalName}, ${entity?uncap_first}.get${field.capitalName}());
               }
          </#if>

      </#list>
      return new LayTableResult<>(this.page(new Page<>(page, limit), queryWrapper));
    }

     /**
     * 新增
     */
     @Override
      public  ResponseResult add(${entity}  ${entity?uncap_first}) {
         this.save(${entity?uncap_first});
         return ResponseResult.success();
      }

     /**
     * 编辑
     */
     @Override
     public   ResponseResult update(${entity}  ${entity?uncap_first}) {
         this.updateById(${entity?uncap_first});
         return ResponseResult.success();
     }

     /**
     * 删除
     */
     @Override
     public  ResponseResult delete(Long id) {
        this.removeById(id);
        return ResponseResult.success();
     }
}
</#if>
